/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package controller;

import client.Client;
import securedchatui.ChatWindow;

/**
 *
 * @author Mohamed
 */
public class ClientController {

    private ChatWindow window;
    private Client client;
    private static ClientController instance;

    private ClientController(ChatWindow window) {
        this.window = window;
    }

    public static ClientController getInstance(ChatWindow window)
    {
        if(instance == null)
            instance = new ClientController(window);
        return instance;
    }


    public void connectToServer(String ipAddress, int port, String username, String password)
    {
        client = new Client(username, password);
        client.initializeClient(ipAddress, port);
    }

    public void sendMessage(String message)
    {
        client.sendNewMessage(message);
    }

    public void addUser(String username) {
        window.addUser(username);
    }

    public void addMessage(String username, String message) {
        window.addMessage(username + ": " + message);
    }
}
